﻿<%@ Page Title="Manage Endpoints" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="ManageEndpoints.aspx.cs" Inherits="NIntegrate.Configuration.UI.ManageEndpoints" ValidateRequest="false" MaintainScrollPositionOnPostback="true" %>
<%@ Import Namespace="NIntegrate.Configuration"%>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2>Manage Endpoints</h2>
    <div class="bottomhyperlink"><img alt="Add new endpoint" src="Images/plus.gif" /><asp:LinkButton 
            ID="btnShowAddNewPanel" runat="server" Text="Add new endpoint" 
            onclick="btnShowAddNewPanel_Click"></asp:LinkButton></div>
    <br />
    <asp:GridView CssClass="gridview"
        ID="gvEndpoints" runat="server" 
        DataSourceID="dsEndpoints"
        DataKeyNames="Endpoint_id"
        AllowSorting="true"
        AutoGenerateDeleteButton="true"
        AutoGenerateColumns="false"
        AutoGenerateEditButton="true" onrowcommand="gvEndpoints_RowCommand">
        <Columns>
            <asp:TemplateField HeaderText="EndpointName" SortExpression="EndpointName">
                <ItemTemplate>
                    <%#Eval("EndpointName")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbEndpointName" runat="server" MaxLength="100" Text='<%#Bind("EndpointName") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="tbEndpointNameRequired" runat="server"
                        ControlToValidate="tbEndpointName" EnableClientScript="false"
                        ErrorMessage="Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Address/ListenUri" SortExpression="EndpointAddress">
                <ItemTemplate>
                    <%#Eval("EndpointAddress")%><br /><%#Eval("ListenUri")%><br /><%# Eval("ListenUriMode_id") == DBNull.Value ? string.Empty : ((EndpointListenUriMode)Eval("ListenUriMode_id")).ToString()%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbEndpointAddress" runat="server" Text='<%#Bind("EndpointAddress") %>'></asp:TextBox><br />
                    ListenUri:<br />
                    <asp:TextBox ID="tbListenUri" runat="server" Text='<%#Bind("ListenUri") %>'></asp:TextBox><br />
                    ListenUriMode:<br />
                    <asp:DropDownList ID="ddlListenUriModes" runat="server" SelectedValue='<%# Bind("ListenUriMode_id") %>'>
                        <asp:ListItem Text="None" Value=""></asp:ListItem>
                        <asp:ListItem Text="Explicit" Value="1"></asp:ListItem>
                        <asp:ListItem Text="Unique" Value="2"></asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>                        
            <asp:TemplateField HeaderText="Behavior" SortExpression="EndpointBehavior_id">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlEndpointBehaviors" runat="server" SelectedValue='<%# Bind("EndpointBehavior_id") %>' Enabled="false" DataTextField="BehaviorName" DataValueField="Behavior_id" DataSourceID="dsEndpointBehaviors" AppendDataBoundItems="true">
                        <asp:ListItem Text="None" Value=""></asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlEndpointBehaviors" runat="server" SelectedValue='<%# Bind("EndpointBehavior_id") %>' DataTextField="BehaviorName" DataValueField="Behavior_id" DataSourceID="dsEndpointBehaviors" AppendDataBoundItems="true">
                        <asp:ListItem Text="None" Value=""></asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="Binding/BindingNamespace" SortExpression="Binding_id">
                <ItemTemplate>
                    <asp:DropDownList ID="ddlBindings" runat="server" SelectedValue='<%# Bind("Binding_id") %>' Enabled="false" DataTextField="BindingName" DataValueField="Binding_id" DataSourceID="dsBindings">
                    </asp:DropDownList><br />
                    <%# Eval("BindingNamespace")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="ddlBindings" runat="server" SelectedValue='<%# Bind("Binding_id") %>' DataTextField="BindingName" DataValueField="Binding_id" DataSourceID="dsBindings">
                    </asp:DropDownList><br />
                    Namespace:<br />
                    <asp:TextBox ID="tbBindingNamespace" runat="server" Text='<%# Bind("BindingNamespace") %>'></asp:TextBox>
                </EditItemTemplate>
            </asp:TemplateField>  
            <asp:TemplateField HeaderText="ServiceContract" SortExpression="ServiceContract">
                <ItemTemplate>
                    <%#Eval("ServiceContract")%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbServiceContract" runat="server" MaxLength="100" Text='<%#Bind("ServiceContract") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="tbServiceContractRequired" runat="server"
                        ControlToValidate="tbServiceContract" EnableClientScript="false"
                        ErrorMessage="Required"></asp:RequiredFieldValidator>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="IdentityXML" SortExpression="IdentityXML">
                <ItemTemplate>
                    <%# Eval("IdentityXML") == DBNull.Value ? string.Empty : Server.HtmlEncode((string)Eval("IdentityXML"))%>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="tbIdentityXML" runat="server" Text='<%#Bind("IdentityXML") %>' TextMode="MultiLine" Rows="3"></asp:TextBox>                   
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ClientBehaviors">
                <ItemTemplate>
                    <asp:LinkButton ID="btnViewClientBehaviors" runat="server" Text="Manage ClientBehaviors" CommandName="Select" CommandArgument='<%# "ViewClientBehaviors|" + Eval("Endpoint_id") %>'></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>            
        </Columns>
        <SelectedRowStyle BackColor="LightYellow" />
    </asp:GridView>
    <asp:Panel ID="panelBottom" runat="server" CssClass="panelBottom">
        <asp:DetailsView ID="dvAddEndpoint" runat="server" Visible="false"
            DataSourceID="dsEndpoints" DefaultMode="Insert"
            AutoGenerateRows="false"
            AutoGenerateInsertButton="true"
            CssClass="detailstable" onitemcommand="dvAddEndpoint_ItemCommand" 
            oniteminserted="dvAddEndpoint_ItemInserted">
            <HeaderTemplate>
                <h5>XML Templates:</h5>
                <a target="_blank" href="XmlTemplates/Identity.xml">Identity</a>
            </HeaderTemplate>            
            <Fields>
                <asp:TemplateField HeaderText="EndpointName">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbEndpointName" runat="server" MaxLength="100" Text='<%#Bind("EndpointName") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="tbEndpointNameRequired" runat="server"
                            ControlToValidate="tbEndpointName" EnableClientScript="false"
                            ErrorMessage="Required"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Address/ListenUri">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbEndpointAddress" runat="server" Text='<%#Bind("EndpointAddress") %>'></asp:TextBox><br />
                        ListenUri:<br />
                        <asp:TextBox ID="tbListenUri" runat="server" Text='<%#Bind("ListenUri") %>'></asp:TextBox><br />
                        ListenUriMode:<br />
                        <asp:DropDownList ID="ddlListenUriModes" runat="server" SelectedValue='<%# Bind("ListenUriMode_id") %>'>
                            <asp:ListItem Text="None" Value=""></asp:ListItem>
                            <asp:ListItem Text="Explicit" Value="1"></asp:ListItem>
                            <asp:ListItem Text="Unique" Value="2"></asp:ListItem>
                        </asp:DropDownList>
                    </InsertItemTemplate>
                </asp:TemplateField>                        
                <asp:TemplateField HeaderText="Behavior">
                    <InsertItemTemplate>
                        <asp:DropDownList ID="ddlEndpointBehaviors" runat="server" SelectedValue='<%# Bind("EndpointBehavior_id") %>' DataTextField="BehaviorName" DataValueField="Behavior_id" DataSourceID="dsEndpointBehaviors" AppendDataBoundItems="true">
                            <asp:ListItem Text="None" Value=""></asp:ListItem>
                        </asp:DropDownList>
                    </InsertItemTemplate>
                </asp:TemplateField>  
                <asp:TemplateField HeaderText="Binding/BindingNamespace">
                    <InsertItemTemplate>
                        <asp:DropDownList ID="ddlBindings" runat="server" SelectedValue='<%# Bind("Binding_id") %>' DataTextField="BindingName" DataValueField="Binding_id" DataSourceID="dsBindings">
                        </asp:DropDownList><br />
                        Namespace:<br />
                        <asp:TextBox ID="tbBindingNamespace" runat="server" Text='<%# Bind("BindingNamespace") %>'></asp:TextBox>
                    </InsertItemTemplate>
                </asp:TemplateField>  
                <asp:TemplateField HeaderText="ServiceContract">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbServiceContract" runat="server" MaxLength="100" Text='<%#Bind("ServiceContract") %>'></asp:TextBox>
                        <asp:RequiredFieldValidator ID="tbServiceContractRequired" runat="server"
                            ControlToValidate="tbServiceContract" EnableClientScript="false"
                            ErrorMessage="Required"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="IdentityXML">
                    <InsertItemTemplate>
                        <asp:TextBox ID="tbIdentityXML" runat="server" Text='<%#Bind("IdentityXML") %>' TextMode="MultiLine" Rows="3"></asp:TextBox>                   
                    </InsertItemTemplate>
                </asp:TemplateField>            
            </Fields>
        </asp:DetailsView>
        <asp:Panel ID="panelClientBehaviors" runat="server" Visible="false">
            <div class="bottomhyperlink"><img alt="Add new clientbehavior" src="Images/plus.gif" /><asp:LinkButton 
                    ID="btnShowSubAddNewPanel" runat="server" Text="Add new clientbehavior" 
                    onclick="btnShowSubAddNewPanel_Click"></asp:LinkButton></div>
            <br />
            <asp:GridView CssClass="gridview"
                ID="gvClientBehaviors" runat="server" 
                DataSourceID="dsClientBehaviors"
                DataKeyNames="Endpoint_id,ClientFarm_id"
                AllowSorting="true"
                AutoGenerateDeleteButton="true"
                AutoGenerateColumns="false"
                EmptyDataText="No ClientBehaviors for selected Endpoint"
                AutoGenerateEditButton="true" onrowcommand="gvClientBehaviors_RowCommand">
                <Columns>
                    <asp:TemplateField HeaderText="Endpoint" SortExpression="Endpoint_id">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlEndpoints" runat="server" SelectedValue='<%# Bind("Endpoint_id") %>' DataSourceID="dsEndpoints" DataTextField="EndpointName" DataValueField="Endpoint_id" Enabled="false"></asp:DropDownList>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlEndpoints" runat="server" SelectedValue='<%# Bind("Endpoint_id") %>' DataSourceID="dsEndpoints" DataTextField="EndpointName" DataValueField="Endpoint_id"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="ClientFarm" SortExpression="ClientFarm_id">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlClientFarms" runat="server" SelectedValue='<%# Bind("ClientFarm_id") %>' DataSourceID="dsFarms" DataTextField="FarmName" DataValueField="Farm_id" Enabled="false"></asp:DropDownList>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlClientFarms" runat="server" SelectedValue='<%# Bind("ClientFarm_id") %>' DataSourceID="dsFarms" DataTextField="FarmName" DataValueField="Farm_id"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="ClientBehavior" SortExpression="ClientEndpointBehavior_id">
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlClientBehaviors" runat="server" SelectedValue='<%# Bind("ClientEndpointBehavior_id") %>' DataSourceID="dsEndpointBehaviors" DataTextField="BehaviorName" DataValueField="Behavior_id" Enabled="false"></asp:DropDownList>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="ddlClientBehaviors" runat="server" SelectedValue='<%# Bind("ClientEndpointBehavior_id") %>' DataSourceID="dsEndpointBehaviors" DataTextField="BehaviorName" DataValueField="Behavior_id"></asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
            <asp:Panel ID="panelAddClientBehavior" runat="server" CssClass="panelBottom" Visible="false">
                <asp:HiddenField ID="hidSelectedEndpoint" runat="server" />
                <asp:DetailsView ID="dvAddClientBehavior" runat="server"
                    DataSourceID="dsClientBehaviors" DefaultMode="Insert"
                    AutoGenerateRows="false"
                    AutoGenerateInsertButton="true"
                    CssClass="detailstable" onitemcommand="dvAddClientBehavior_ItemCommand" 
                    oniteminserted="dvAddClientBehavior_ItemInserted" 
                    ondatabound="dvAddClientBehavior_DataBound">
                    <Fields>
                        <asp:TemplateField HeaderText="Endpoint">
                            <InsertItemTemplate>
                                <asp:DropDownList ID="ddlEndpoints" runat="server" SelectedValue='<%# Bind("Endpoint_id") %>' DataSourceID="dsEndpoints" DataTextField="EndpointName" DataValueField="Endpoint_id"></asp:DropDownList>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="ClientFarm">
                            <InsertItemTemplate>
                                <asp:DropDownList ID="ddlClientFarms" runat="server" SelectedValue='<%# Bind("ClientFarm_id") %>' DataSourceID="dsFarms" DataTextField="FarmName" DataValueField="Farm_id"></asp:DropDownList>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="ClientBehavior">
                            <InsertItemTemplate>
                                <asp:DropDownList ID="ddlClientBehaviors" runat="server" SelectedValue='<%# Bind("ClientEndpointBehavior_id") %>' DataSourceID="dsEndpointBehaviors" DataTextField="BehaviorName" DataValueField="Behavior_id"></asp:DropDownList>
                                <asp:RequiredFieldValidator ID="ddlClientBehaviorsRequired" runat="server"
                                    ControlToValidate="ddlClientBehaviors" EnableClientScript="false"
                                    ErrorMessage="Required"></asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                    </Fields>
                </asp:DetailsView>            
            </asp:Panel>
        </asp:Panel>        
    </asp:Panel>
    <ni:QueryDataSource ID="dsEndpoints" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsBindings" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsFarms" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsEndpointBehaviors" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
    <ni:QueryDataSource ID="dsClientBehaviors" runat="server" UseLocalQueryService="true">
    </ni:QueryDataSource>
</asp:Content>
